﻿using System;
using System.Collections;
using System.Text;

namespace TADF.Com.Alpha.Core.View.Component
{
    public class Component
    {
        protected bool _isVisible;
        protected string _id;
        //protected UIProperty property;

        public Component() { }

        public Component(string id)
        {
            _id = id;
        }

        public void SetVisible(bool b)
        {
            _isVisible = b;
        }

        //public void SetProperty(UIProperty p)
        //{
        //    this.property = p;
        //}

        public string ToXML()
        {
            string tag = GetTypeName();
            return "<" + tag + " id='" + _id + "'>"
                    + AttrXml()
                    + "</" + tag + ">";
        }

        public string AttrXml()
        {
            if (_isVisible)
                return "<visible>" + (_isVisible ? 1 : 0) + "</visible>" + PropToXml();
            else
                return PropToXml();
        }

        public string WrapCData(object data){
		if(data == null)
			return "";
        //if(typeof(data) is DateTime)
        //    return string.Format((DateTime)data,"YY-MM-DD");
		return "<![CDATA[" + data + "]]>";
	}

        protected void BindParam(object param)
        {
        }

        public string GetTypeName()
        {
            return GetType().Name;
        }

        private string PropToXml()
        {
            //if (property == null)
            //    return "";

            StringBuilder sb = new StringBuilder(1024);
            return sb.ToString();
        }
    }
}
